#ifndef UNICODE2UTF8_H
#define UNICODE2UTF8_H
#include <iostream>
#include <iconv.h>

#define OUTLEN 255

using namespace std;

// ´úÂë×ª»»²Ù×÷Àà
class CodeConverter {
	private:
		iconv_t cd;
	public:
		// ¹¹Ôì
		CodeConverter(const char *from_charset, const char *to_charset) {
			cd = iconv_open(to_charset, from_charset);
		}

		// Îö¹¹
		~CodeConverter() {
			iconv_close(cd);
		}

		// ×ª»»Êä³ö
		int convert(char *inbuf, int inlen, char *outbuf, int outlen) {
			char **pin = &inbuf;
			char **pout = &outbuf;

			memset(outbuf, 0, outlen);
			return iconv(cd, pin, (size_t *)&inlen, pout, (size_t *)&outlen);
		}
};

#endif

